moneyLook.UI.createDetailRepay = function(id)
	{
		var data = moneyLook.DB.getDetailRepay(id);
		
		var win = Ti.UI.createWindow({
			title:'Detail : ' + id,
			layout:'vertical',
			backgroundColor:'#fff'
		});
		
		var topView = Ti.UI.createView({
			top:0,
			left:0,
			layout:'horizontal'
		});
		
		var whoLabel = Ti.UI.createLabel({
			text:'Qui?',
			left:10,
		});
		
		var whoResponseLabel = Ti.UI.createLabel({
			text:data.to,
			left:10,
		});
		
		topView.add(whoLabel);
		topView.add(whoResponseLabel);
		win.add(topView);
		
		var middleView = Ti.UI.createView({
			top:10,
			left:0,
			layout:'horizontal'
		});
		
		var howMuchLabel = Ti.UI.createLabel({
			text:'Combien?',
			left:10,
		});
		
		var howMuchResponseLabel = Ti.UI.createLabel({
			text:data.montant,
			left:10,
		});
		
		middleView.add(howMuchLabel);
		middleView.add(howMuchResponseLabel);
		win.add(middleView);
		
		var bottomView = Ti.UI.createView({
			top:10,
			left:0,
			layout:'horizontal'
		});
		
		var showMapButton = Ti.UI.createButton({
			title:'Voir sur map',
			left:10
		});
		
		showMapButton.addEventListener('click', function(e){
			moneyLook.tabRepay.open(moneyLook.UI.createMapWindow(data.longitude, data.latitude));
		});
		
		var showPhotoButton = Ti.UI.createButton({
			title:'Voir photo',
			left:10,
		});
		
		showPhotoButton.addEventListener('click', function(e){
			moneyLook.tabRepay.open(moneyLook.UI.createPhotoWindow(data.imgPath));
		});
		
		bottomView.add(showMapButton);
		bottomView.add(showPhotoButton);
		win.add(bottomView);
		
		
		return win;
	};
	
	moneyLook.UI.createMapWindow = function(longitude, latitude)
	{
		
		var win = Ti.UI.createWindow({
			title:'Map',
		});
		
		if(longitude != null && latitude != null)
		{
			var place = Ti.Map.createAnnotation({
			  latitude:latitude,
			  longitude:longitude,
			  title:'Place',
			  pincolor:Ti.Map.ANNOTATION_GREEN,
			  animate:true,
			});
			var mapView = Ti.Map.createView({
			  mapType: Ti.Map.STANDARD_TYPE,
			  animate:true,
			  regionFit:true,
			  userLocation:false,
			  annotations:[place]
			});
			win.add(mapView);
		}
		return win;
	};
	
	moneyLook.UI.createPhotoWindow = function(imgPath)
	{
		var win = Ti.UI.createWindow({
			title:'Map',
		});
		if(imgPath != null)
		{
			var imageView = Ti.UI.createImageView({
				width:150,
				height:200,
				image:imgPath,
				top:40,
				left:10
			});
			win.add(imageView);
		}
				
	    return win;
	};


========================================
moneyLook.UI.createAddRepayWindow = function(){
		var win = Ti.UI.createWindow({
			title:'Ajouter une redevance',
			layout:'vertical',
			backgroundColor:'#fff'
		});
		
		var tbName = Ti.UI.createTextField({
			hintText:'note pour la redevance',
			top:10,
			left:10,
			width:200
		});
		
		win.add(tbName);
		
		var tbMontant = Ti.UI.createTextField({
			hintText:'montant',
			top:10,
			left:10,
			width:200,
		});
		
		win.add(tbMontant);
		
		var labelForPicker = Ti.UI.createLabel({
			text:"Qui vous doit de l'argent ?",
			top:10,
			left:10,
		});
		
		win.add(labelForPicker);
		
		var picker = moneyLook.UI.createContactPicker();
		win.add(picker);
		
		var buttonTakeAPhoto = Ti.UI.createButton({
			title:'Prendre une photo?',
			top:10,
			left:10,
		});
		var imgPath = null;
		buttonTakeAPhoto.addEventListener('click', function(e){
			Titanium.Media.showCamera({
		
				success:function(event)
				{
					var cropRect = event.cropRect;
					var image = event.media;
			
					Ti.API.debug('Our type was: '+event.mediaType);
					if(event.mediaType == Ti.Media.MEDIA_TYPE_PHOTO)
					{
						var f = Titanium.Filesystem.getFile(Titanium.Filesystem.applicationDataDirectory,'camera_photo.png');
						f.write(image);
						imgPath = f.nativePath;
					}
					else
					{
						alert("got the wrong type back ="+event.mediaType);
					}
				},
				cancel:function()
				{
				},
				error:function(error)
				{
					// create alert
					var a = Titanium.UI.createAlertDialog({title:'Camera'});
			
					// set message
					if (error.code == Titanium.Media.NO_CAMERA)
					{
						a.setMessage('Please run this test on device');
					}
					else
					{
						a.setMessage('Unexpected error: ' + error.code);
					}
			
					// show alert
					a.show();
				},
				saveToPhotoGallery:true,
				allowEditing:true,
				mediaTypes:[Ti.Media.MEDIA_TYPE_VIDEO,Ti.Media.MEDIA_TYPE_PHOTO]
			});
		
		});
		
		win.add(buttonTakeAPhoto);
		
		
		
		var buttonAdd = Ti.UI.createButton({
			title:'Ajouter',
			top:10,
			left:10
		});
		
		var longitude = null;
		var latitude = null;
		
		if (Titanium.Geolocation.locationServicesEnabled === false)
		{
			Titanium.UI.createAlertDialog({title:'My app', message:'Your device has geo turned off - turn it on.'}).show();
		}
		else
		{
			Ti.Geolocation.preferredProvider = "gps";
			Titanium.Geolocation.distanceFilter = 10;
			Titanium.Geolocation.getCurrentPosition( function(e) {
					if (!e.success) {
						alert('Could not retrieve location');
						return;
					}
					longitude = e.coords.longitude;
					latitude = e.coords.latitude;
					
			});
		}
		
		buttonAdd.addEventListener('click', function(e){
			if(longitude != null && latitude != null && imgPath != null)
			{
				moneyLook.DB.addRepayWithAll(tbName.value, tbMontant.value , picker.getSelectedRow(0).title, longitude, latitude, imgPath);
			}
			else
			{
				if(longitude != null && latitude != null)
				{
					moneyLook.DB.addRepayWithGeo(tbName.value, tbMontant.value , picker.getSelectedRow(0).title, longitude, latitude);
				}
				else{
					moneyLook.DB.addRepay(tbName.value, tbMontant.value , picker.getSelectedRow(0).title);
				}
				
			}
		});
		
		win.add(buttonAdd);
		
		return win;
	};